package com.hxzy.controller.login;

import com.hxzy.common.resp.R;
import com.hxzy.common.util.TokenService;
import com.hxzy.controller.login.req.AdminLoginReq;
import com.hxzy.controller.login.resp.AdminLoginResp;
import com.hxzy.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/api")
public class LoginController {

    @Autowired
    private SysUserService  sysUserService;
    @Autowired
    private TokenService tokenService;

     @PostMapping(value = "/login")
     public R<String>  login(@RequestBody AdminLoginReq req){
         AdminLoginResp adminLoginResp= this.sysUserService.login(req);
         //把对象换令牌
         String token = this.tokenService.createToken(adminLoginResp);

         return R.okHasData(token);
     }

}
